﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using RookieLibSharp.Log;
using RookieLibSharp.Configuration;
namespace BirthdayRemainder
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool bCreate;
            //保证程序只能运行一个
            using (Mutex mu = new Mutex(true, Application.ProductName, out bCreate))
            {
                if (bCreate)
                {
                    try
                    {
                        Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                        //处理UI线程异常   
                        Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(LogHelper.Application_ThreadException);
                        //处理非UI线程异常   
                        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(LogHelper.CurrentDomain_UnhandledException);
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        Application.Run(new FrmMain());
                        Cfg.Terminate();
                    }
                    catch (System.Exception ex)
                    {
                        RookieLibSharp.Progress.ProgressManager.CloseProcessFrm();
                        LogHelper.WriteLog(LogErrorLevel.Error, typeof(Program), ex);

                    }

                }
                else
                {
                    MessageBox.Show("程序已经运行!");
                }
            }
        }

    }
}
